/*
import java.util.concurrent.PriorityBlockingQueue;

//创建一个类，表示一个任务
class MyTask implements Comparable<MyTask>{
    //任务具体要干啥
    private Runnable runnable;
    //任务具体啥时候干，保存认为要执行的毫秒级时间戳
    private long time;

    //delay是一个时间间隔，不是绝对的时间戳的值
    public MyTask(Runnable runnable,long delay){
        this.runnable = runnable;
        this.time = System.currentTimeMillis() + delay;
    }

    public void run(){
        runnable.run();
    }

    public long getTime(){
        return time;
    }
    @Override
    public int compareTo(MyTask o) {
        // 到底是谁见谁, 才是一个时间小的在前? 需要咱们背下来.
        return (int) (this.time - o.time);
    }

}

class MyTimer{
    //定时器内部要能够存放多个任务
    private PriorityBlockingQueue queue = new PriorityBlockingQueue();

    public void schedule(Runnable runnable, long delay){
        MyTask task = new MyTask(runnable, delay);
        queue.put(task);
        synchronized (locker){
            locker.notify();
        }
    }

    private Object locker = new Object();

    public MyTimer(){
        Thread thread = new Thread(() ->{
            while(true){
                try {
                    MyTask task = (MyTask) queue.take();
                    long curTime = System.currentTimeMillis();
                    if(curTime < task.getTime()){
                        //时间没到，把任务再塞回到队列中
                        queue.put(task);
                        synchronized (locker){
                            locker.wait(task.getTime() - curTime);
                        }
                    }else{
                        task.run();
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        thread.start();
    }
}

public class Test {
    public static void main(String[] args) {
        MyTimer timer = new MyTimer();
        timer.schedule(new Runnable() {
            @Override
            public void run() {
                System.out.println("hello");
            }
        },3000);
        System.out.println("main");
    }
}
*/
